package com.vogue.flowmeter.ui.activity;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.vogue.flowmeter.R;
import com.vogue.flowmeter.api.event.DashboardMessageEvent;
import com.vogue.flowmeter.api.event.MessageExternalEvent;
import com.vogue.flowmeter.profile.BleProfileService;
import com.vogue.flowmeter.profile.data.VogueBleWriteData;
import com.vogue.flowmeter.util.Constant;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 外置设备参数设置
 */
public class ExternalSettingsActivity extends AppCompatActivity {

    @BindView(R.id.et_external_settings_range)
    EditText etExternalSettingsRange;
    @BindView(R.id.et_external_settings_damping)
    EditText etExternalSettingsDamping;
    @BindView(R.id.et_external_settings_caliber)
    EditText etExternalSettingsCaliber;
    @BindView(R.id.et_external_settings_output_mode)
    EditText etExternalSettingsOutputMode;
    @BindView(R.id.et_external_settings_gross_unit)
    EditText etExternalSettingsGrossUnit;
    @BindView(R.id.et_external_settings_excitation_time)
    EditText etExternalSettingsExcitationTime;
    @BindView(R.id.et_external_settings_excitation_frequency)
    EditText etExternalSettingsExcitationFrequency;
    @BindView(R.id.et_external_settings_manual_zero)
    EditText etExternalSettingsManualZero;
    @BindView(R.id.et_external_settings_flow_to)
    EditText etExternalSettingsFlowTo;
    @BindView(R.id.et_external_settings_small_signal_excision)
    EditText etExternalSettingsSmallSignalExcision;
    @BindView(R.id.et_external_settings_frequency_coefficient)
    EditText etExternalSettingsFrequencyCoefficient;
    @BindView(R.id.et_external_settings_main_board_coefficient)
    EditText etExternalSettingsMainBoardCoefficient;
    @BindView(R.id.et_external_settings_wide_excitation_zero)
    EditText etExternalSettingsWideExcitationZero;
    @BindView(R.id.et_external_settings_standard_flow_rate_1)
    EditText etExternalSettingsStandardFlowRate1;
    @BindView(R.id.et_external_settings_measured_velocity_1)
    EditText etExternalSettingsMeasuredVelocity1;
    @BindView(R.id.et_external_settings_standard_flow_rate_2)
    EditText etExternalSettingsStandardFlowRate2;
    @BindView(R.id.et_external_settings_measured_velocity_2)
    EditText etExternalSettingsMeasuredVelocity2;
    @BindView(R.id.et_external_settings_standard_flow_rate_3)
    EditText etExternalSettingsStandardFlowRate3;
    @BindView(R.id.et_external_settings_measured_velocity_3)
    EditText etExternalSettingsMeasuredVelocity3;
    @BindView(R.id.et_external_settings_standard_flow_rate_4)
    EditText etExternalSettingsStandardFlowRate4;
    @BindView(R.id.et_external_settings_measured_velocity_4)
    EditText etExternalSettingsMeasuredVelocity4;
    @BindView(R.id.et_external_settings_standard_flow_rate_5)
    EditText etExternalSettingsStandardFlowRate5;
    @BindView(R.id.et_external_settings_measured_velocity_5)
    EditText etExternalSettingsMeasuredVelocity5;
    @BindView(R.id.et_external_settings_standard_flow_rate_6)
    EditText etExternalSettingsStandardFlowRate6;
    @BindView(R.id.et_external_settings_measured_velocity_6)
    EditText etExternalSettingsMeasuredVelocity6;
    @BindView(R.id.et_external_settings_standard_flow_rate_7)
    EditText etExternalSettingsStandardFlowRate7;
    @BindView(R.id.et_external_settings_measured_velocity_7)
    EditText etExternalSettingsMeasuredVelocity7;
    @BindView(R.id.et_external_settings_empty_pipe_threshold)
    EditText etExternalSettingsEmptyPipeThreshold;
    @BindView(R.id.et_external_settings_atc_signal_reference)
    EditText etExternalSettingsAtcSignalReference;
    @BindView(R.id.et_external_settings_narrow_excitation_zero)
    EditText etExternalSettingsNarrowExcitationZero;
    @BindView(R.id.et_external_settings_table_no)
    EditText etExternalSettingsTableNo;
    @BindView(R.id.et_external_settings_upper_limit_alarm_point)
    EditText etExternalSettingsUpperLimitAlarmPoint;
    @BindView(R.id.et_external_settings_lower_limit_alarm_point)
    EditText etExternalSettingsLowerLimitAlarmPoint;
    @BindView(R.id.et_external_settings_receipt_space)
    EditText etExternalSettingsReceiptSpace;


    @BindView(R.id.lay_et_external_settings_range_background)
    LinearLayout layEtExternalSettingsRangeBackground;
    @BindView(R.id.lay_et_external_settings_damping_background)
    LinearLayout layEtExternalSettingsDampingBackground;
    @BindView(R.id.lay_et_external_settings_caliber_background)
    LinearLayout layEtExternalSettingsCaliberBackground;
    @BindView(R.id.lay_et_external_settings_output_mode_background)
    LinearLayout layEtExternalSettingsOutputModeBackground;
    @BindView(R.id.lay_et_external_settings_gross_unit_background)
    LinearLayout layEtExternalSettingsGrossUnitBackground;
    @BindView(R.id.lay_et_external_settings_excitation_time_background)
    LinearLayout layEtExternalSettingsExcitationTimeBackground;
    @BindView(R.id.lay_et_external_settings_excitation_frequency_background)
    LinearLayout layEtExternalSettingsExcitationFrequencyBackground;
    @BindView(R.id.lay_et_external_settings_manual_zero_background)
    LinearLayout layEtExternalSettingsManualZeroBackground;
    @BindView(R.id.lay_et_external_settings_flow_to_background)
    LinearLayout layEtExternalSettingsFlowToBackground;
    @BindView(R.id.lay_et_external_settings_small_signal_excision_background)
    LinearLayout layEtExternalSettingsSmallSignalExcisionBackground;
    @BindView(R.id.lay_et_external_settings_frequency_coefficient_background)
    LinearLayout layEtExternalSettingsFrequencyCoefficientBackground;
    @BindView(R.id.lay_et_external_settings_main_board_coefficient_background)
    LinearLayout layEtExternalSettingsMainBoardCoefficientBackground;
    @BindView(R.id.lay_et_external_settings_wide_excitation_zero_background)
    LinearLayout layEtExternalSettingsWideExcitationZeroBackground;

    @BindView(R.id.lay_et_external_settings_standard_flow_rate_1_background)
    LinearLayout layEtExternalSettingsStandardFlowRate1Background;
    @BindView(R.id.lay_et_external_settings_measured_velocity_1_background)
    LinearLayout layEtExternalSettingsMeasuredVelocity1Background;
    @BindView(R.id.lay_et_external_settings_standard_flow_rate_2_background)
    LinearLayout layEtExternalSettingsStandardFlowRate2Background;
    @BindView(R.id.lay_et_external_settings_measured_velocity_2_background)
    LinearLayout layEtExternalSettingsMeasuredVelocity2Background;
    @BindView(R.id.lay_et_external_settings_standard_flow_rate_3_background)
    LinearLayout layEtExternalSettingsStandardFlowRate3Background;
    @BindView(R.id.lay_et_external_settings_measured_velocity_3_background)
    LinearLayout layEtExternalSettingsMeasuredVelocity3Background;
    @BindView(R.id.lay_et_external_settings_standard_flow_rate_4_background)
    LinearLayout layEtExternalSettingsStandardFlowRate4Background;
    @BindView(R.id.lay_et_external_settings_measured_velocity_4_background)
    LinearLayout layEtExternalSettingsMeasuredVelocity4Background;
    @BindView(R.id.lay_et_external_settings_standard_flow_rate_5_background)
    LinearLayout layEtExternalSettingsStandardFlowRate5Background;
    @BindView(R.id.lay_et_external_settings_measured_velocity_5_background)
    LinearLayout layEtExternalSettingsMeasuredVelocity5Background;
    @BindView(R.id.lay_et_external_settings_standard_flow_rate_6_background)
    LinearLayout layEtExternalSettingsStandardFlowRate6Background;
    @BindView(R.id.lay_et_external_settings_measured_velocity_6_background)
    LinearLayout layEtExternalSettingsMeasuredVelocity6Background;
    @BindView(R.id.lay_et_external_settings_standard_flow_rate_7_background)
    LinearLayout layEtExternalSettingsStandardFlowRate7Background;
    @BindView(R.id.lay_et_external_settings_measured_velocity_7_background)
    LinearLayout layEtExternalSettingsMeasuredVelocity7Background;


    @BindView(R.id.lay_et_external_settings_empty_pipe_threshold_background)
    LinearLayout layEtExternalSettingsEmptyPipeThresholdBackground;
    @BindView(R.id.lay_et_external_settings_atc_signal_reference_background)
    LinearLayout layEtExternalSettingsAtcSignalReferenceBackground;
    @BindView(R.id.lay_et_external_settings_narrow_excitation_zero_background)
    LinearLayout layEtExternalSettingsNarrowExcitationZeroBackground;
    @BindView(R.id.lay_et_external_settings_table_no_background)
    LinearLayout layEtExternalSettingsTableNoBackground;
    @BindView(R.id.lay_et_external_settings_upper_limit_alarm_point_background)
    LinearLayout layEtExternalSettingsUpperLimitAlarmPointBackground;
    @BindView(R.id.lay_et_external_settings_lower_limit_alarm_point_background)
    LinearLayout layEtExternalSettingsLowerLimitAlarmPointBackground;
    @BindView(R.id.lay_et_external_settings_receipt_space_background)
    LinearLayout layEtExternalSettingsReceiptSpaceBackground;


    @BindView(R.id.btn_external_settings_write)
    Button btnExternalSettingsWrite;

    protected BleProfileService.LocalBinder localBinder;



    private ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            localBinder = (BleProfileService.LocalBinder) service;
            Log.e(UpdateHexActivity.class.getName(), "serviceConnection");
            if (localBinder.isReady()) {
                //showToast("设备就绪");
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };
    private void registerBroadcastReceiver() {
        //注册监听
        IntentFilter stateChangeFilter = new IntentFilter(
                BluetoothAdapter.ACTION_STATE_CHANGED);
        IntentFilter connectedFilter = new IntentFilter(
                BluetoothDevice.ACTION_ACL_CONNECTED);
        IntentFilter disConnectedFilter = new IntentFilter(
                BluetoothDevice.ACTION_ACL_DISCONNECTED);
        registerReceiver(stateChangeReceiver, stateChangeFilter);
        registerReceiver(stateChangeReceiver, connectedFilter);
        registerReceiver(stateChangeReceiver, disConnectedFilter);
    }

    private BroadcastReceiver stateChangeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) {
                //连接上了
            } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
                //蓝牙连接被切断
                checkConnection();
                return;
            }
        }
    };
    private void checkConnection() {
        if (localBinder.isReady()) {
        } else {
            new AlertDialog.Builder(this)
                    .setTitle("温馨提示")
                    .setMessage("蓝牙已经断开，点击确定跳转到设备列表选择一个蓝牙设备进行连接！")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            DashboardMessageEvent conEvent=new DashboardMessageEvent("Home","连接中断了");
                            EventBus.getDefault().post(conEvent);
                            finish();
                        }
                    })
                    .show();
            //showToast("设备未就绪,请先连接相关设备");
            return;
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_external_settings);
        ButterKnife.bind(this);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        Intent intent = new Intent(ExternalSettingsActivity.this, BleProfileService.class);
        bindService(intent, serviceConnection, BIND_AUTO_CREATE);
        registerBroadcastReceiver();
        ActionBar actionBar=getSupportActionBar();
        if(actionBar != null){
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        setTitle("外部参数设置");

    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish(); // back button
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @OnClick(R.id.btn_external_settings_write)
    public void onClick() {
        hideKeyboard(this);
        checkConnection();
        layEtExternalSettingsRangeBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsDampingBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsCaliberBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsOutputModeBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsGrossUnitBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsExcitationTimeBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsExcitationFrequencyBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsManualZeroBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsFlowToBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsSmallSignalExcisionBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsFrequencyCoefficientBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsMainBoardCoefficientBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsWideExcitationZeroBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsStandardFlowRate1Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsMeasuredVelocity1Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsStandardFlowRate2Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsMeasuredVelocity2Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsStandardFlowRate3Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsMeasuredVelocity3Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsStandardFlowRate4Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsMeasuredVelocity4Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsStandardFlowRate5Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsMeasuredVelocity5Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsStandardFlowRate6Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsMeasuredVelocity6Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsStandardFlowRate7Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsMeasuredVelocity7Background.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsEmptyPipeThresholdBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsAtcSignalReferenceBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsNarrowExcitationZeroBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsTableNoBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsUpperLimitAlarmPointBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsLowerLimitAlarmPointBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);
        layEtExternalSettingsReceiptSpaceBackground.setBackgroundResource(R.drawable.ic_background_et_nomal);

        if (localBinder.isReady()) {
            //TODO

            String externalSettingsRange = etExternalSettingsRange.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsRange))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsRange, Constant.ExternalSettingsRange));
            String externalSettingsDamping = etExternalSettingsDamping.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsDamping))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsDamping, Constant.ExternalSettingsDamping));
            String externalSettingsCaliber = etExternalSettingsCaliber.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsCaliber))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsCaliber, Constant.ExternalSettingsCaliber));
            String externalSettingsOutputMode = etExternalSettingsOutputMode.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsOutputMode))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsOutputMode, Constant.ExternalSettingsOutputMode));
            String externalSettingsGrossUnit = etExternalSettingsGrossUnit.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsGrossUnit))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsGrossUnit, Constant.ExternalSettingsGrossUnit));
            String externalSettingsExcitationTime = etExternalSettingsExcitationTime.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsExcitationTime))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsExcitationTime, Constant.ExternalSettingsExcitationTime));
            String externalSettingsExcitationFrequency = etExternalSettingsExcitationFrequency.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsExcitationFrequency))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsExcitationFrequency, Constant.ExternalSettingsExcitationFrequency));
            String externalSettingsManualZero = etExternalSettingsManualZero.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsManualZero))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsManualZero, Constant.ExternalSettingsManualZero));
            String externalSettingsFlowTo = etExternalSettingsFlowTo.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsFlowTo))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsFlowTo, Constant.ExternalSettingsFlowTo));

            String externalSettingsSmallSignalExcision = etExternalSettingsSmallSignalExcision.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsSmallSignalExcision))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsSmallSignalExcision, Constant.ExternalSettingsSmallSignalExcision));
            String externalSettingsFrequencyCoefficient = etExternalSettingsFrequencyCoefficient.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsFrequencyCoefficient))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsFrequencyCoefficient, Constant.ExternalSettingsFrequencyCoefficient));
            String externalSettingsMainBoardCoefficient = etExternalSettingsMainBoardCoefficient.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsMainBoardCoefficient))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsMainBoardCoefficient, Constant.ExternalSettingsMainBoardCoefficient));
            String externalSettingsWideExcitationZero = etExternalSettingsWideExcitationZero.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsWideExcitationZero))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsWideExcitationZero, Constant.ExternalSettingsWideExcitationZero));

            //流速 被流速
            String externalSettingsStandardFlowRate1 = etExternalSettingsStandardFlowRate1.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsStandardFlowRate1))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsStandardFlowRate1, Constant.ExternalSettingsStandardFlowRate1));
            String externalSettingsMeasuredVelocity1 = etExternalSettingsMeasuredVelocity1.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsMeasuredVelocity1))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsMeasuredVelocity1, Constant.ExternalSettingsMeasuredVelocity1));
            String externalSettingsStandardFlowRate2 = etExternalSettingsStandardFlowRate2.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsStandardFlowRate2))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsStandardFlowRate2, Constant.ExternalSettingsStandardFlowRate2));
            String externalSettingsMeasuredVelocity2 = etExternalSettingsMeasuredVelocity2.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsMeasuredVelocity2))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsMeasuredVelocity2, Constant.ExternalSettingsMeasuredVelocity2));
            String externalSettingsStandardFlowRate3 = etExternalSettingsStandardFlowRate3.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsStandardFlowRate3))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsStandardFlowRate3, Constant.ExternalSettingsStandardFlowRate3));
            String externalSettingsMeasuredVelocity3 = etExternalSettingsMeasuredVelocity3.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsMeasuredVelocity3))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsMeasuredVelocity3, Constant.ExternalSettingsMeasuredVelocity3));
            String externalSettingsStandardFlowRate4 = etExternalSettingsStandardFlowRate4.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsStandardFlowRate4))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsStandardFlowRate4, Constant.ExternalSettingsStandardFlowRate4));
            String externalSettingsMeasuredVelocity4 = etExternalSettingsMeasuredVelocity4.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsMeasuredVelocity4))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsMeasuredVelocity4, Constant.ExternalSettingsMeasuredVelocity4));
            String externalSettingsStandardFlowRate5 = etExternalSettingsStandardFlowRate5.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsStandardFlowRate5))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsStandardFlowRate5, Constant.ExternalSettingsStandardFlowRate5));
            String externalSettingsMeasuredVelocity5 = etExternalSettingsMeasuredVelocity5.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsMeasuredVelocity5))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsMeasuredVelocity5, Constant.ExternalSettingsMeasuredVelocity5));
            String externalSettingsStandardFlowRate6 = etExternalSettingsStandardFlowRate6.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsStandardFlowRate6))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsStandardFlowRate6, Constant.ExternalSettingsStandardFlowRate6));
            String externalSettingsMeasuredVelocity6 = etExternalSettingsMeasuredVelocity6.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsMeasuredVelocity6))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsMeasuredVelocity6, Constant.ExternalSettingsMeasuredVelocity6));
            String externalSettingsStandardFlowRate7 = etExternalSettingsStandardFlowRate7.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsStandardFlowRate7))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsStandardFlowRate7, Constant.ExternalSettingsStandardFlowRate7));
            String externalSettingsMeasuredVelocity7 = etExternalSettingsMeasuredVelocity7.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsMeasuredVelocity7))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsMeasuredVelocity7, Constant.ExternalSettingsMeasuredVelocity7));


            String externalSettingsEmptyPipeThreshold = etExternalSettingsEmptyPipeThreshold.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsEmptyPipeThreshold))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsEmptyPipeThreshold, Constant.ExternalSettingsEmptyPipeThreshold));
            String externalSettingsAtcSignalReference = etExternalSettingsAtcSignalReference.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsAtcSignalReference))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsAtcSignalReference, Constant.ExternalSettingsAtcSignalReference));
            String externalSettingsNarrowExcitationZero = etExternalSettingsNarrowExcitationZero.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsNarrowExcitationZero))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsNarrowExcitationZero, Constant.ExternalSettingsNarrowExcitationZero));
            String externalSettingsTableNo = etExternalSettingsTableNo.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsTableNo))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsTableNo, Constant.ExternalSettingsTableNo));
            String externalSettingsUpperLimitAlarmPoint = etExternalSettingsUpperLimitAlarmPoint.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsUpperLimitAlarmPoint))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsUpperLimitAlarmPoint, Constant.ExternalSettingsUpperLimitAlarmPoint));
            String externalSettingsLowerLimitAlarmPoint = etExternalSettingsLowerLimitAlarmPoint.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsLowerLimitAlarmPoint))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsLowerLimitAlarmPoint, Constant.ExternalSettingsLowerLimitAlarmPoint));
            String externalSettingsReceiptSpace = etExternalSettingsReceiptSpace.getText().toString().trim();
            if (!TextUtils.isEmpty(externalSettingsReceiptSpace))
                localBinder.read(VogueBleWriteData.ExternalParameters(externalSettingsReceiptSpace, Constant.ExternalSettingsReceiptSpace));

        }else {
            showToast("设备未就绪");
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        unbindService(serviceConnection);
    }
    /**
     *
     * @param activity
     */
    public static void hideKeyboard(Activity activity) {
        View view = activity.findViewById(android.R.id.content);
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    /**
     *
     * @param activity
     */
    public static void showKeyboard(Activity activity) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }
    /**
     * @param msg
     */
    protected void showToast(String msg) {
        if (true) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(ExternalSettingsActivity.this, msg, Toast.LENGTH_LONG).show();
                }
            });
        }
    }

    /**
     * 订阅消息  获取到消息类型  修改UI
     *
     * @param event
     */
    @Subscribe
    public void onMessageEvent(MessageExternalEvent event) {
        Log.e(ExternalSettingsActivity.class.getName(), event.toString());
        String meaning="";
        switch (event.getAddress()) {
            case "0021":
                meaning="量程";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsRangeBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsRange.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsRangeBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsRange.setText(event.getMessage());
                }

                break;
            case "0023":
                meaning="阻尼";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsDampingBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsDamping.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsDampingBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsDamping.setText(event.getMessage());
                }

                break;
            case "0025":
                meaning="口径";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsCaliberBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsCaliber.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsCaliberBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsCaliber.setText(event.getMessage());
                }

                break;
            case "0060":
                meaning="频率输出模式";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsOutputModeBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsOutputMode.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsOutputModeBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsOutputMode.setText(event.getMessage());
                }

                break;
            case "0061":
                meaning="总量单位";
                if ("rx".equals(event.getDirection())){

                }else if ("tx".equals(event.getDirection())){

                }
                layEtExternalSettingsGrossUnitBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                etExternalSettingsGrossUnit.setText(event.getMessage());
                break;
            case "0071":
                meaning="励磁时间";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsExcitationTimeBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsExcitationTime.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsExcitationTimeBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsExcitationTime.setText(event.getMessage());
                }

                break;
            case "0072":
                meaning="励磁频率";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsExcitationFrequencyBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsExcitationFrequency.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsExcitationFrequencyBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsExcitationFrequency.setText(event.getMessage());
                }

                break;
            case "0073":
                meaning="手动零点";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsManualZeroBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsManualZero.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsManualZeroBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsManualZero.setText(event.getMessage());
                }

                break;
            case "0074":
                meaning="流向";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsFlowToBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsFlowTo.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsFlowToBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsFlowTo.setText(event.getMessage());
                }

                break;
            case "0075":
                meaning="小信号切除";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsSmallSignalExcisionBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsSmallSignalExcision.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsSmallSignalExcisionBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsSmallSignalExcision.setText(event.getMessage());
                }

                break;
            case "0069":
                meaning="频率系数";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsFrequencyCoefficientBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsFrequencyCoefficient.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsFrequencyCoefficientBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsFrequencyCoefficient.setText(event.getMessage());
                }

                break;
            case "0031":
                meaning="主板系数";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsMainBoardCoefficientBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsMainBoardCoefficient.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsMainBoardCoefficientBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsMainBoardCoefficient.setText(event.getMessage());
                }

                break;
            case "0081":
                meaning="宽励磁零点";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsWideExcitationZeroBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsWideExcitationZero.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsWideExcitationZeroBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsWideExcitationZero.setText(event.getMessage());
                }

                break;
            case "0083":
                meaning="标准流速点1";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate1Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsStandardFlowRate1.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate1Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsStandardFlowRate1.setText(event.getMessage());
                }

                break;
            case "0085":
                meaning="被测流速点1";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity1Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsMeasuredVelocity1.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity1Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsMeasuredVelocity1.setText(event.getMessage());
                }

                break;
            case "0087":
                meaning="标准流速点2";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate2Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsStandardFlowRate2.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate2Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsStandardFlowRate2.setText(event.getMessage());
                }

                break;
            case "0089":
                meaning="被测流速点2";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity2Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsMeasuredVelocity2.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity2Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsMeasuredVelocity2.setText(event.getMessage());
                }

                break;
            case "0091":
                meaning="标准流速点3";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate3Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsStandardFlowRate3.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate3Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsStandardFlowRate3.setText(event.getMessage());
                }

                break;
            case "0093":
                meaning="被测流速点3";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity3Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsMeasuredVelocity3.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity3Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsMeasuredVelocity3.setText(event.getMessage());
                }

                break;
            case "0094":
                meaning="标准流速点4";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate4Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsStandardFlowRate4.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate4Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsStandardFlowRate4.setText(event.getMessage());
                }

                break;
            case "0097":
                meaning="被测流速点4";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity4Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsMeasuredVelocity4.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity4Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsMeasuredVelocity4.setText(event.getMessage());
                }

                break;
            case "0099":
                meaning="标准流速点5";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate5Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsStandardFlowRate5.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate5Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsStandardFlowRate5.setText(event.getMessage());
                }

                break;
            case "0101":
                meaning="被测流速点5";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity5Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsMeasuredVelocity5.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity5Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsMeasuredVelocity5.setText(event.getMessage());
                }

                break;
            case "0103":
                meaning="标准流速点6";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate6Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsStandardFlowRate6.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate6Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsStandardFlowRate6.setText(event.getMessage());
                }

                break;
            case "0105":
                meaning="被测流速点6";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity6Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsMeasuredVelocity6.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity6Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsMeasuredVelocity6.setText(event.getMessage());
                }

                break;
            case "0107":
                meaning="标准流速点7";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate7Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsStandardFlowRate7.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsStandardFlowRate7Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsStandardFlowRate7.setText(event.getMessage());
                }

                break;
            case "0109":
                meaning="被测流速点7";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity7Background.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsMeasuredVelocity7.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsMeasuredVelocity7Background.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsMeasuredVelocity7.setText(event.getMessage());
                }

                break;
            case "0113":
                meaning="空管阀值";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsEmptyPipeThresholdBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsEmptyPipeThreshold.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsEmptyPipeThresholdBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsEmptyPipeThreshold.setText(event.getMessage());
                }

                break;
            case "0115":
                meaning="空管阀值基准";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsAtcSignalReferenceBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsAtcSignalReference.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsAtcSignalReferenceBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsAtcSignalReference.setText(event.getMessage());
                }

                break;
            case "0117":
                meaning="窄励磁零点";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsNarrowExcitationZeroBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsNarrowExcitationZero.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsNarrowExcitationZeroBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsNarrowExcitationZero.setText(event.getMessage());
                }

                break;
            case "0033":
                meaning="表号";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsTableNoBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsTableNo.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsTableNoBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsTableNo.setText(event.getMessage());
                }

                break;
            case "0035":
                meaning="上限报警点";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsUpperLimitAlarmPointBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsUpperLimitAlarmPoint.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsUpperLimitAlarmPointBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsUpperLimitAlarmPoint.setText(event.getMessage());
                }

                break;
            case "0036":
                meaning="下限报警点";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsLowerLimitAlarmPointBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsLowerLimitAlarmPoint.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsLowerLimitAlarmPointBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsLowerLimitAlarmPoint.setText(event.getMessage());
                }

                break;
            case "0037":
                meaning="回执空间";
                if ("rx".equals(event.getDirection())){
                    layEtExternalSettingsReceiptSpaceBackground.setBackgroundResource(R.drawable.ic_background_et_blue);
                    etExternalSettingsReceiptSpace.setText(event.getMessage());
                }else if ("tx".equals(event.getDirection())){
                    layEtExternalSettingsReceiptSpaceBackground.setBackgroundResource(R.drawable.ic_background_et_accent);
                    etExternalSettingsReceiptSpace.setText(event.getMessage());
                }
                break;
            default:
                meaning="未知地址";
                showToast("解析失败");
        }

        //发送事件出去
/*        RecordMessageEvent recordMessageEvent = new RecordMessageEvent(event.getControl()+"["+meaning+"]", event.toString());
        EventBus.getDefault().post(recordMessageEvent);*/
    }

}